/**
 * Created by PhpStorm.
 * User: ly
 * Date: 2017\11\28 0020
 * Time: 16:06
 */

/*选择省后获取城市 【完善信息】【详情编辑】*/
function select_change(s) {
    $.ajax({
        url: "get-country-list",
        data: {'id': s},
        type: "post",
        async: false,
        dataType: "json",
        success: function (data, status) {
            var str = '<option value>--请选择市--</option>';
            if (data.code == 200) {
                var content = data.data.res;//获取的内容主体
                for (var i = 0; i < content.length; i++) {
                    str += '<option value=' + content[i].id + '>' + content[i].title + '</option>';
                }
            }
            $('#city').html(str);
        }
});
}
/*资产包下载报告显示框*/
$(".asset-package-editing-download").click(function () {
    $.get('show-down-page', function (msg) {
        $('#modal_div').html(msg);
        $("#modal_div").modal();
    })
});
/*资产包下载报告  提交*/
$("body").delegate("#downLoadSetup", "click", function () {
// $("#downLoadSetup").click(function () {
    var packageId=$("#downPackageId").val();
    var setUpFile=false;
    if($("#setUpFile").is(":checked")){
        setUpFile=true;
    }
    var type=0;
    if($("#typeDY").is(":checked")){
        type+=parseInt($("#typeDY").val(),10);
    }
    if($("#typeHH").is(":checked")){
        type+=parseInt($("#typeHH").val(),10);
    }
    if(type>0||setUpFile){
        if(setUpFile) window.open('/package/show-down-page?setUpFile='+setUpFile+'&packageid='+packageId);
        if(type>0) window.location.href="/package/down-projects?type="+type+'&packageid='+packageId;
        $("#modal_div").modal('hide');
    }else{
        layer.alert('请选择要下载的文件类型');
    }
});

/*资产包基本信息提交  EidtBase  【完善信息】【详情编辑】*/
$("body").delegate("#sumitpackageinfo", "click", function () {
    if(!$("#infoForm").valid()){
        return;
    }
    var title = $("#titlename").val();
    var type = $("#typename").children('.btn-primary').attr('typeid');
    var creditorname = $("#creditorname").val();
    var province = $("#province").val();
    var city = $("#city").val();
    var principal = $("#principal").val().replace(/,/g,'');
    var interest = $("#interest").val().replace(/,/g,'');
    var hushu = $("#hushu").val();
    var limit_collection = $("#limit_collection").val();
    var origin = $("#origin").val();
    var detail = $("#detail").val();

    $.ajax({
        url: "eidt-base",
        data: {
            'title': title,
            'type': type,
            'creditor': creditorname,
            'province': province,
            'city': city,
            'principal': principal,
            'interest': interest,
            'hushu': hushu,
            'limit_collection':limit_collection,
            'origin':origin,
            'detail': detail
        },
        type: "post",
        async: false,
        dataType: "json",
        success: function (data, status) {//code  message
            // if(data.status==false){
            //     layer.alert(data.msg);
            // }
            if (data.code == 200) {
                // if(window.location.pathname.indexOf('detailinfo')>=0){//from：资产包编辑页
                var url = '/package/edit-base-info?o=s';
                $.get(url, function (msg) {
                    $('.perfect-information').html(msg);
                })
                // }
            }
            layer.alert(data.message);//alert(data.message);
        }
    });
});

/*资产包基本信息 取消编辑  EidtBase  【详情编辑】*/
$("body").delegate("#cancelpackageinfo", "click", function () {
    var url = '/package/edit-base-info?o=s';
    $.get(url, function (msg) {
        $('.perfect-information').html(msg);
    })
});
/*转让信息提交表单【完善信息】【详情编辑】
* contentType: "application/json
* hcontact hphone haddress hemail hposition hremark
* lcontact lphone laddress lemail lposition lremark
* serialize()
* */
$("body").delegate("#subtransfer", "click", function () {
    if(!$("#transferForm").valid()){
        return;
    }
    var transfertype = $("#transfertype").children('.btn-primary').attr('transferid');
    var methodtype = $("#methodtype").children('.btn-primary').attr('methodid');
    var wish = $("#wish").val();
    var detail = $("#tdetail").val();
    var data = {
        hcontact: $("#hcontact").val(),
        hphone: $("#hphone").val(),
        haddress: $("#haddress").val(),
        hemail: $("#hemail").val(),
        hposition: $("#hposition").val(),
        hremark: $("#hremark").val(),
        lcontact: $("#lcontact").val(),
        lphone: $("#lphone").val(),
        laddress: $("#laddress").val(),
        lemail: $("#lemail").val(),
        lposition: $("#lposition").val(),
        lremark: $("#lremark").val(),
        transfer: transfertype,
        expected_transfer:$("#expected_transfer").val(),
        method: methodtype,
        wish: wish,
        detail: detail
    };
    $.ajax({
        url: "eidt-transfer",
        data: data,
        type: "post",
        async: false,
        dataType: "json",
        success: function (data, status) { //code  message
            if (data.code == 200) {
                // if(window.location.pathname.indexOf('detailinfo')>=0){//from：资产包编辑页
                var url = '/package/edit-transfer-info?o=s';
                $.get(url, function (msg) {
                    $('.Transfer-information').html(msg);
                })
                // }
            }
            layer.alert(data.message);//alert(data.message);
        }
    });
});

/*转让信息 取消编辑 【详情编辑】*/
$("body").delegate("#canceltransfer", "click", function () {
    var url = '/package/edit-transfer-info?o=s';
    $.get(url, function (msg) {
        $('.Transfer-information').html(msg);
    })
});
/**
 * 流转、前期处置及维护情况-提交----【信息完善】
 *表单id ：historyForm(完善页面)
 * */
$("body").delegate("#subHistory", "click", function () {
// $("#subHistory").click(function () {
    $.ajax({
        type: 'post',
        url: 'add-transfer-history',
        data: $("#historyForm").serialize(),
        dataType: "json",
        success: function (data) {//成功后跳转到我的新建资产包列表
            if (data.code == 200) {
                var url = '/package/edit-history-info?o=s';
                $.get(url, function (msg) {
                    $('.History-information').html(msg);
                })
            }
            layer.alert(data.message);//(data.message);

        }
    });
});
/*
* 流转、前期处置及维护 编辑【详情编辑】【完善信息】
*
* */
// $("#subHistoryUpdate").click(function(){
//         alert('空的');
// });
$("body").delegate("#subHistoryUpdate", "click", function () {
    $.ajax({
        type: 'post',
        url: 'update-transfer-history',
        data: $("#historyForm").serialize(),
        dataType: "json",
        success: function (data) {//成功后跳转到我的新建资产包列表
            if (data.code == 200) {
                var url = '/package/edit-history-info?o=s';
                $.get(url, function (msg) {
                    $('.History-information').html(msg);
                })
            }
            layer.alert(data.message);//alert(data.message);
        }
    });
});
/**
 * 流转、前期处置及维护情况--删除---【完善信息】【详情编辑】
 * */
$("body").delegate("#delHistory", "click", function () {
    if (confirm("确认要删除？")) {
        var chks = $(".maintenance-tbody input:checked");//获取所有选中的checkbox,chks是一个元素数组
        // 循环遍历每个被选中的checkbox,删除父元素tr
        chks.each(function () {
            delFlag = true;
            if ($(this).val() != 'on') {//删除数据库中的流转记录
                $.ajax({
                    url: "del-transfer-history",
                    data: {"id": $(this).val()},
                    type: "post",
                    async: false,
                    dataType: "json",
                    success: function (data, status) { //code  message
                        if (data.code != 200) {//成功后删除页面元素
                            delFlag = false;
                        }
                        layer.alert(data.message);//alert(data.message);
                    }
                });
            }
            if (delFlag) {
                var delindex = $(this).parent('td').parent('tr').index();
                var liindex = delindex + 1;
                $(".maintenance-addpop li").eq(liindex).remove();
                $(this).parent('td').parent('tr').remove();
            }
        });
    }
});
// $("#delHistory").click(function () {
//     var chks = $(".maintenance-tbody input:checked");//获取所有选中的checkbox,chks是一个元素数组
//     // 循环遍历每个被选中的checkbox,删除父元素tr
//     chks.each(function(){
//     	var delindex = $(this).parent('td').parent('tr').index();
//     	var liindex = delindex + 1 ;
//     	$(".maintenance-addpop li").eq(liindex).remove();
//     	$(this).parent('td').parent('tr').remove();
//     });
// });


/**
 * 删除资产包中某个项目 【完善信息】
 * @@传值projectid
 * */
$("#delproject li").click(function () {
    var obj = $(this);
    var projectid = $(this).attr('projectid');
    if (confirm("确认要删除？")) {
        //alert("选择删除了");
        $.ajax({
            url: "del-project-list",
            data: {"id": projectid},
            type: "post",
            async: false,
            dataType: "json",
            success: function (data, status) { //code  message
                if (data.code == 200) {
                    $("#projectTr" + data.data.res).remove();
                    $(obj).remove();
                    layer.alert(data.message);//alert(data.message);
                }

            }
        });

    }
});
/*资产包详情-项目删除（一个或批量删除）*/
$("body").delegate(".del-projects", "click", function () {
    // var tableObj=$(this).parents('table');
    var tableObj=$(this).parents('ul').prev('div').find('table').children('tbody');;
    var ids=new Array();
    var i=0;
    tableObj.find("input:checkbox").each(function(){
        if($(this).is(':checked')){
            if($.inArray($(this).val(),ids)==-1) {
                ids[i]=$(this).val();
                i++;
            }
         }
    });
    if(i>0){
        if (confirm("确认要删除？")) {
            $.ajax({
                type: 'post',
                url: 'del-project-list',
                data: {'id':ids},
               dataType: "json",
                success: function (data) {//成功后跳转到我的新建资产包列表
                    layer.alert(data.message);//alert(data.message);
                    if (data.code == 200) {
                        tableObj.find("input:checkbox").each(function(){
                            if($(this).is(':checked')){
                                $(this).parents('tr').remove();
                            }
                        });
                         // alert('000000');
                        // if(tableObj.find('tr').length==0){
                        //     alert('8888');
                        //     tableObj.html('<tr><td colspan=46 style= "width: 1126px; " class= "text-center" >暂无数据</td></tr>');
                        // }
                        
                    }
                }
            });
        }
    }else{
        layer.alert('请选择要删除的项目');// alert('请选择要删除的项目');
    }
});
/*提交的xls 文件中的项目列表 【完善信息】*/
$("body").delegate("#projectSubmit", "click", function (e) {
    e.preventDefault();
    var useFlag=true;
    var objName='',inputName='',inputValue='',inputChange='';
    $('#projectlist tbody tr td input').each(function(){
       objName=$(this).attr('name');//principal interest benxi
       inputName=objName.replace(/[0-9]/ig,'');
       inputValue=$(this).val();
        if(inputName=='principal'||inputName=='interest'){//||inputName=='benxi' 本金利息格式检测
            if(inputValue.indexOf(',')>0){//含有逗号
                inputChange=Number(inputValue.replace(/,/ig,''));
                inputChange=inputChange.toLocaleString();
            }else{//不含有逗号
                inputChange=Number(inputValue);
            }
            if(inputChange!=inputValue &&inputChange+'.00'!=inputValue&&inputChange+'0'!=inputValue){
                alert(inputChange+'-----'+inputValue);
                useFlag=false;
                return false;
            }
        }
    });
    if(useFlag){
        $('#projectlist tbody tr td input').each(function(){
            objName=$(this).attr('name');//principal interest benxi
            inputName=objName.replace(/[0-9]/ig,'');
            inputValue=$(this).val();
            if(inputName=='principal'||inputName=='interest'){//||inputName=='benxi' 本金利息格式统一去掉逗号
                if(inputValue.indexOf(',')>0){//含有逗号
                    inputChange=Number(inputValue.replace(/,/ig,''));
                    $(this).val(inputChange);
                }
            }
        });
        $.ajax({
            type: 'post',
            url: 'edit-project-list',
            data: $("#projectListForm").serialize(),
            dataType: "json",
            success: function (data) {//成功后跳转到我的新建资产包列表
                // layer.alert(data.message);
                layer.msg(data.message, {
                    time: 3000, //3s后自动关闭
                    end: function(){
                        if (data.code == 200) {
                            //跳转页面[我的新建记录]
                            window.location.href = '/my-package/get-my-package?packageGroup=2';
                        }
                    }
                });

            }
        });
    }else{
        layer.alert('金额格式有误！');
    }
});
/*资产包详情-项目列表-新增项目*/
$("body").delegate("#subAddProject", "click", function () {
    if(!$("#addProject").valid()){
        return;
    }
    $.ajax({
        type: 'post',
        url: 'add-project',
        data: $("#addProject").serialize(),
        dataType: "json",
        success: function (data) {
            layer.alert(data.message);
            if (data.code == 200) {
                $("#modal_div").modal('hide');
                var typeid=data.data.count;
                var url='';
                var cs=[];
                if(typeid==2){//刷新抵押类列表
                    if($("#projectListDY .pagination").length>0){
                        cs=$("#projectListDY .pagination").find('.active').find('a').attr('href').split('?');
                    }
                    url='/package/project-d-y?'+cs[1];
                    $.get(url,function(msg){
                        $('#projectListDY').html(msg);
                    })
                }else{//刷新混合类列表
                    if($("#projectListHH .pagination").length>0){
                        cs=$("#projectListHH .pagination").find('.active').find('a').attr('href').split('?');
                    }
                    url='/package/project-h-h?'+cs[1];
                    $.get(url,function(msg){
                        $('#projectListHH').html(msg);
                    })
                }
            }
        }
    });
});
//   $("#projectSubmit").click(function () {});
/*点击基本信息编辑按钮后  【详情编辑】【完善信息】*/
$("body").delegate("#baseInfoEdit", "click", function (e) {
    e.preventDefault();
    var url = '/package/edit-base-info?o=e';
    $.get(url,function (msg) {
        if(msg.indexOf("<div")==-1 ){
            layer.alert(msg);
        }else{
            $('.perfect-information').html(msg);
        }
    })
});
/*点击转让信息编辑按钮后 【详情编辑】【完善信息】*/
$("body").delegate("#transferInfoEdit", "click", function (e) {
    e.preventDefault();
    var url = '/package/edit-transfer-info?o=e';
    $.get(url,function (msg) {
        if(msg.indexOf("<div")==-1 ){
            layer.alert(msg);
        }else{
            $('.Transfer-information').html(msg);
        }
    })
});

/*点击流转、前期处置及维护情况信息编辑按钮后 【详情编辑】【完善信息】*/
$("body").delegate("#historyInfoEdit", "click", function (e) {
    e.preventDefault();
    var url = '/package/edit-history-info?o=e';
    $.get(url,function (msg) {
        if(msg.indexOf("<div")==-1 ){
            layer.alert(msg);
        }else{
            $('.History-information').html(msg);
        }
    })
});
/*异步分页跳转 项目列表混合类 projectList1 */
$("body").delegate("#projectListHH .pagination a,#projectListHH table th > a","click",function(e) {
    e.preventDefault();
    var tabId=$(".notedit-nav-ul-guarantee").find('.active').attr('tabId');// li .active .attr('tabId')
    var cs=$(this).attr('href').split('?');
    var url='/package/project-h-h?tabID='+tabId+'&'+cs[1];
    $.get(url,function(msg){
         $('#projectListHH').html(msg);
    })
});
//异步混合类选择分页显示调试 设置每页显示条数
$("body").delegate("#per-page-hh","change",function(e) {
    var urlBorrower=$('#projectListHH table thead tr th').eq(2).find('a').attr('href');
    if(urlBorrower.indexOf('detail-info')>0){
        urlBorrower='/index.php/package/project-h-h?';
    }else{
        urlBorrower=urlBorrower.replace('sort=borrower','');
    }
    urlBorrower+='per-page-hh='+$(this).val();
    $.get(urlBorrower,function(msg){
        $('#projectListHH').html(msg);
    })
});
/*异步分页跳转 项目列表抵押类 projectList2 projectListDY*/
$("body").delegate(".projectList2 .pagination a,.projectList2 table th > a","click",function(e) {
    e.preventDefault();
    var cs=$(this).attr('href').split('?');
    var tabId=$(".notedit-nav-ul-guaranty").find('.active').attr('tabId');// li .active .attr('tabId')
    var url='/package/project-d-y?tabID='+tabId+'&'+cs[1];
    $.get(url,function(msg){
        $('#projectListDY').html(msg);
    })
});
//异步抵押类类选择分页显示调试 设置每页显示条数
$("body").delegate("#per-page-dy","change",function(e) {
    var getVal=$(this).attr('getVal');
    if(getVal.indexOf('detail-info')>0){
        getVal='/index.php/package/project-d-y?';
    }else{
        getVal='/index.php/package/project-d-y?'+getVal+'&';
    }
    getVal+='per-page-dy='+$(this).val();
    $.get(getVal,function(msg){
        $('#projectListDY').html(msg);
    })
});
/*两个项目列表中全选 select-on-check-all*/
$("body").delegate(".select-on-check-all","click",function() {
   //  e.preventDefault();
    var flag=$(this).is(':checked');
    var obj=$(this).parents('ul').prev('div').find('table').children('tbody');
  // alert(obj.html());
    var objTd='';
    obj.children('tr').each(function(){
        //alert($(this).html());
        objTd=$(this).children('td').eq(0);
        objTd.find('input').attr('checked',flag);
    })
});
// $("body").delegate(".select-on-check-all-dy","click",function() {
//     //  e.preventDefault();
//     var flag=$(this).is(':checked');
//     var obj=$("#myTable2").children('tbody');
//     //alert(obj.html());
//     var objTd='';
//     obj.children('tr').each(function(){
//         objTd=$(this).children('td').eq(0);
//         objTd.children('input').attr('checked',flag);
//     })
// });
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}
/*modal框的调用 asset-package-editing-adds 新增项目*/
$("body").delegate(".asset-package-editing-adds","click",function() {
    var packageid=GetQueryString('packageid');
    var typeid=$(this).attr('typeid');
    $.ajax({
        url: "add-project",
        data: {'packageid': packageid,'type':typeid},
        type: "post",
        success: function (data) {
            $("#modal_div").html(data);
            $("#modal_div").modal();
        }
    });
});

/*下载项目列表信息生成xls asset-package-editing-move*/
$("body").delegate(".asset-package-editing-down","click",function() {
    // var tableObj=$(this).parents('table');
    var tableObj=$(this).parents('ul').prev('div').find('table').children('tbody');
    var typeid=$(this).attr('typeid');//改的值
    var ids=new Array();
    var i=0;
    tableObj.find("input:checkbox").each(function(){
        if($(this).is(':checked')){
            trObj=$(this).parents('tr');
            if($.inArray($(this).val(),ids)==-1) ids[i]=$(this).val();
            i++;
        }
    });
    if(i>0){
        window.location.href="/package/down-projects?type="+typeid+'&ids='+ids;
    }else{
        layer.alert('请选择要下载的项目');
    }
});

/*移动到抵押类列表和抵用到混合类列表asset-package-editing-move*/
$("body").delegate(".asset-package-editing-move","click",function() {
    // var tableObj=$(this).parents('table');
    var tableObj=$(this).parents('ul').prev('div').find('table').children('tbody');
    var typeid=$(this).attr('typeid');//改的值
    var ids=new Array();
    var i=0;
    tableObj.find("input:checkbox").each(function(){
        if($(this).is(':checked')){
            trObj=$(this).parents('tr');
            if($.inArray($(this).val(),ids)==-1) ids[i]=$(this).val();
            i++;
        }
    });
    if(i>0){
        $.ajax({
            url: "move",
            data: {'ids':ids,'type':typeid},
            type: "post",
            dataType: "json",
            success: function (data) {
               if(data.code==200){
                   tableObj.find("input:checkbox").each(function(){
                       if($(this).is(':checked')){
                           $(this).parents('tr').remove();
                       }
                       /*刷新项目列表*/
                       var cs=new Array();cs[1]='';
                       var url='';
                       if(typeid==2){//刷新抵押类列表
                           if($("#projectListDY .pagination").length>0){
                               cs=$("#projectListDY .pagination").find('.active').find('a').attr('href').split('?');
                           }
                           url='/package/project-d-y?'+cs[1];
                           $.get(url,function(msg){
                               $('#projectListDY').html(msg);
                           })
                       }else{//刷新混合类列表
                           if($("#projectListHH .pagination").length>0){
                               cs=$("#projectListHH .pagination").find('.active').find('a').attr('href').split('?');
                           }
                           url='/package/project-h-h?'+cs[1];
                           $.get(url,function(msg){
                               $('#projectListHH').html(msg);
                           })
                       }
                   });
               }
                layer.alert(data.message);
            }
        });
    }else{
        layer.alert('请选择要移动的项目');
    }

});

/*modal框的调用 asset-package-editing-calculate 自动计算 */
$("body").delegate(".asset-package-editing-calculate","click",function() {
    // var tableObj=$(this).parents('table');
    var tableObj=$(this).parents('ul').prev('div').find('table').children('tbody');
    var typeid=$(this).attr('typeid');
    var trObj;
    var ids=new Array();
    var i=0;
    tableObj.find("input:checkbox").each(function(){
        if($(this).is(':checked')){
            trObj=$(this).parents('tr');
            if($.inArray($(this).val(),ids)==-1) ids[i]=$(this).val();
            i++;
        }
    });
    if(i > 0){
        $.ajax({
            url: "calculate",
            data: {'ids':ids,'type':typeid},
            type: "post",
            success: function (data) {
                $("#modal_div").html(data);
                $("#modal_div").modal();
            }
        });
    }else{
        layer.alert('请选择要计算的项目');//('请选择要计算的项目');
    }
});
/*modal框的调用 asset-package-editing-filtrate 高级筛选弹出框*/
$("body").delegate(".asset-package-editing-filtrate","click",function() {
    var typeid=$(this).attr('typeid');
    var keyWords=$("#keyWordsHH").val();

    $.ajax({
        url: "filtrate",
        data: {'typeid': typeid,'keyWords':keyWords},
        type: "post",
        success: function (data) {
            $("#modal_div").html(data);
            $("#modal_div").modal();
        }
    });
});
/*混合类 关键词搜索*/
$("#searchHH").click(function () {
    var url='project-h-h';
    var divName='#projectListHH';
    var keyWords=$("#keyWordsHH").val();
    $.get('project-h-h?'+'keyWords='+keyWords,function(data){
        $(divName).html(data);
    });
});
/*触发回车提交*/
$(this).keydown(function (e){
    if(e.which == "13"){
        if($(":focus").attr('id')=='keyWordsHH'){
            var url='project-h-h';
            var divName='#projectListHH';
            var keyWords=$("#keyWordsHH").val();
            $.get('project-h-h?'+'keyWords='+keyWords,function(data){
                $(divName).html(data);
            });
        }
    }
})
/*modal框的调用 高级筛选 查询*/
$("body").delegate("#filtrateSub","click",function() {
   // var packageid=GetQueryString('packageid');
    var typeid=$(this).attr('typeid');
    var url='project-h-h';
    var divName='#projectListHH';
    if(typeid==2){
        url='project-d-y';
        divName='#projectListDY';
    }
    //$.get(url,params,function(data,status){});
    $.get(url,$("#filtrateForm").serialize(),function(data){
        $("#modal_div").modal('hide');
        $(divName).html(data);
    });
    // $.ajax({
    //     url:url,
    //     data: $("#filtrateForm").serialize(),
    //     type: "post",
    //     success: function (data) {
    //         $("#modal_div").modal('hide');
    //         $(divName).html(data);
    //     }
    // });
});
// // 只显示亮点项目
function onlyShowLight(e) {
    var typeid=$(e).attr('typeid');
    var url='project-h-h';
    var divName='#projectListHH';
    if(typeid==2){
        url='project-d-y';
        divName='#projectListDY';
    }
    var is_highlights='';
    if($(e).find('img').attr('src')=='/image/assetPackage/turn.png'){//显示亮点项目
        $(e).find('img').attr('src','/image/assetPackage/turnoff.png');
        is_highlights='';
    }else{
        $(e).find('img').attr('src','/image/assetPackage/turn.png');//只显示亮点项目
        is_highlights=1;
    }
    $.get(url+'?is_highlights='+is_highlights,function(data){
        $(divName).html(data);
    });
    // $.ajax({
    //     url:url,
    //     data:{'is_highlights':is_highlights} ,
    //     type: "post",
    //     success: function (data) {
    //         $(divName).html(data);
    //     }
    // });
}
var updateObj='';
/*资产包详情-抵押 项目列表projectListBase*/
$("body").delegate("#projectListBase2 table tbody tr td","click",function() {
    var tbName=$(this).children('input').attr('tb');
    var fdName=$(this).children('input').attr('fd');
    if($(this).index() > 5 || (tbName!=undefined && fdName!=undefined)){
        var content=$(this).children('input').val();
        // var fdShowName=$("#projectListBase2 table thead tr").find('th').eq($(this).index()).html();
        var tbName=$(this).children('input').attr('tb');
        var fdName=$(this).children('input').attr('fd');
        var keyId=0;
        if($(this).children('input').attr('keyId')!=undefined){
             keyId=$(this).children('input').attr('keyId');
        }else{
            keyId=$(this).parent().find('td').eq(0).find('input').val();
        }
        if(keyId>0){
            updateObj=$(this);
            $.ajax({
                url:'show-field-page',
                data:{tb:tbName,fd:fdName,keyId:keyId,fdShowName:'',content:content,type:2} ,
                type: "post",
                success: function (data) {
                    $("#modal_div").html(data);
                    $("#modal_div").modal();
                }
            });
        }else{
            layer.alert('该数据不存在，请在项目详情添加后再编辑！');
        }
    }
});

/*资产包详情-混合类 项目列表projectListBase*/
$("body").delegate("#projectListBase table tbody tr td","click",function() {
    var tbName=$(this).children('span').attr('tb');
    var fdName=$(this).children('span').attr('fd');
    if($(this).index() > 6 || (tbName!=undefined && fdName!=undefined)){
        var content=$(this).children('span').attr('title');
        var objTH=$("#projectListBase table thead tr").find('th').eq($(this).index());
        var fdShowName='';
        if(objTH.find('a').length>0){
            fdShowName=objTH.find('a').html();
        }else{
            fdShowName=objTH.html();
        }
        var keyId=$(this).parent().find('td').eq(0).find('input').val();
        updateObj=$(this);
        $.ajax({
            url:'show-field-page',
            data:{tb:tbName,fd:fdName,keyId:keyId,fdShowName:fdShowName,content:content,type:1} ,
            type: "post",
            success: function (data) {
                $("#modal_div").html(data);
                $("#modal_div").modal();
            }
        });
    }
});
/*资产包详情 编辑每个字段提交接口EditFieldSub*/
$("body").delegate("#EditFieldSub","click",function() {
    var fdName=$("#fd").val();
    var tbName=$("#tb").val();
    var keyId=$("#keyId").val();
    var type=$("#type").val();
    var fdContent='';
    var fdContentShowStr='';
    if(fdName=='industry' || fdName=='mortgage_type'){//industry mortgage_type
        $("#fdContent .active").each(function () {
                if(fdContent) {fdContent+=',';fdContentShowStr+=',';}
                fdContent+=$(this).attr('val');
                fdContentShowStr+=$(this).html();
            }
        );
        //active
    }else if(fdName=='is_first_mortgage' || fdName=='is_first_seal'){//is_first_mortgage is_first_seal
        fdContent=$('#fdContent label input:checked').val();
        fdContentShowStr=(fdContent==1?'是':'否');
    }else {//select
        fdContent=$("#fdContent").val();
        //is_suit management_status enterprise
        if(fdName=='is_suit'|| fdName=='management_status' ||fdName=='enterprise'){
            fdContentShowStr=$("#fdContent").find("option:selected").text();
        }else{
            fdContentShowStr=$("#fdContent").val();
        }
    }
    $.ajax({
        url:'edit-field',
        data:{tb:tbName,fd:fdName,keyId:keyId,content:fdContent} ,
        type: "post",
        dataType: "json",
        success: function (data) {
            layer.alert(data.message);
            if(data.code==200){
                $("#modal_div").modal('hide');
                var searchId='' ;
                if(type==1){//更新混合类列表
                    updateObj.find('span').html(fdContentShowStr);
                    updateObj.find('span').attr('title',fdContentShowStr);
                }else{//更新抵押类列表
                    updateObj.find('input').val(fdContentShowStr);
                }
            }
        }
    });

});





